<template  xmlns:el-form-item="http://www.w3.org/1999/xhtml">
  <el-form ref="ruleFrom" :model="ruleFrom"  label-width="100px">
    <el-page-header content="详情页" @back="goBack" />
    <el-row style="margin-top: 30px">
      <!--基本输入框-->
      <el-col :span="5">
        <el-form-item label="采购编号:" prop="name1">
          {{ruleFrom.procurementId}}
        </el-form-item>
      </el-col>
      <!--基本单选框-->
      <el-col :span="5">
        <el-form-item label="采购人：" prop="name2">
          {{ruleFrom.procurementName}}
        </el-form-item>
      </el-col>
      <!--基本多选框-->
      <el-col :span="8">
        <el-form-item label="创建日期:" prop="subjectId">
          {{ruleFrom.lyhProcurementEntity.procurementDate}}
        </el-form-item>
      </el-col>
      <el-col :span="8">
        <el-form-item label="入库人:" prop="subjectId">
          {{ruleFrom.auditUser}}
        </el-form-item>
      </el-col>
      <el-col :span="8">
        <el-form-item label="入库日期:" prop="subjectId">
          {{ruleFrom.auditDate}}
        </el-form-item>
      </el-col>
    </el-row>
    <!--上传文件-->
    <el-row>
      <el-col :span="20">
        <el-form-item label="退货原因:" prop="fileName">
          <el-input
              v-model="ruleFrom.reportReasonVo"
              :rows="2"
              type="textarea"
              placeholder="请输入退货原因"
          />
        </el-form-item>
      </el-col>


    </el-row>
    <!--数据表格-->
    <el-row>


      <el-col :span="24">
        <el-form-item>
          <el-button style="width:80px;margin-left: 90%" type="primary" @click="insert()">提交申请</el-button>
          <el-table
              :data="tableData[0].lyhProcurementEntity.lyhProcurementDetailsEntities.slice((currentPage-1)*pagesize,currentPage*pagesize)"
              @selection-change="selectionLineChangeHandle"
              border
              style="width: 100%;margin-left: -20px">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column
                prop="drugEntity.drugName"
                label="药品名"
                width="180">
            </el-table-column>
            <el-table-column
                prop="numbers"
                label="药品数量">
              <template #default="scope">

<!--                <el-input placeholder="请输入内容" v-show="scope.row.show" v-model.number="scope.row.numbers"></el-input>-->
                <!--                <span v-show="!scope.row.show">{{scope.row.numbers}}</span>-->
      {{scope.row.numbers}}
              </template>


            </el-table-column>

            <el-table-column
                prop="drugEntity.lyhSupplierEntity.supplierName"
                label="供应商">
            </el-table-column>
            <el-table-column
                prop="drugEntity.drugDate"
                label="生产日期">
            </el-table-column>

            <el-table-column
                prop="drugEntity.drugPrice"
                label="单价/元">
            </el-table-column>

            <el-table-column
                prop="drugEntity.drugPrice"
                label="总价格/元">
              <template #default="scope">

                {{scope.row.numbers * scope.row.drugEntity.drugPrice}}


              </template>
            </el-table-column>
            <el-table-column
                prop="procurementId"
                label="采购编号">
            </el-table-column>


          </el-table>
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>
</template>

<script>
import http, {service} from "@/http/request";
import Cookies from 'js-cookie';
import qs from "qs";

export default {
  data() {
    return {
      reverse: true,

      piCi:'',
      customerData: [],
      ruleFrom:{
        auditId:'',
        reportReasonVo: '',
        meiYon:0,
        procurementName:"",
        auditUser:"",
        reportNameVO:'',
        auditDate:'',
        procurementId:"",
        lyhProcurementEntity:{
          lyhProcurementDetailsEntities:[],
        }
      },
      zhuanhuan:"",
      currentPage:1, //初始页
      pagesize:10,    //    每页的数据
      ruleFrom2:{
        numbers:'',
      },

      dialogVisible: false,
      tableData:[
        {
          lyhProcurementEntity:{
            lyhProcurementDetailsEntities:[],
          }
        }


      ],
      tableDetails:[],
    }


  },

  methods: {

    goBack(){
      this.$router.push({
        path: '/return'
      })
    },

    insert(){
      this.ruleFrom.lyhProcurementEntity.lyhProcurementDetailsEntities=this.tableDetails;
    if (this.ruleFrom.reportReasonVo ==null ){
      this.$message.error("请输入退货原因")
        }else if (this.ruleFrom.lyhProcurementEntity.lyhProcurementDetailsEntities == undefined || this.ruleFrom.lyhProcurementEntity.lyhProcurementDetailsEntities.length <=0){
      this.$message.error("请选择退货药品")
    } else {
      alert(this.ruleFrom.reportNameVO)
        service.post("add-report",this.ruleFrom)
      .then((v) => {
        this.$router.push({
          path: '/return'
        })
        this.$message("申请成功")
      })
}

    },
// 获取当前日期的方法
    getProjectNum () {
      const now = new Date()
      let month = now.getMonth() + 1
      let day = now.getDate()
      let hour = now.getHours()
      let minutes = now.getMinutes()
      let seconds = now.getSeconds()
      month = this.setTimeDateFmt(month)
      hour = this.setTimeDateFmt(hour)
      minutes = this.setTimeDateFmt(minutes)
      seconds = this.setTimeDateFmt(seconds)
      return now.getFullYear().toString() + month.toString() + day + (Math.round(Math.random() * 23 + 100)).toString()
    },

    setTimeDateFmt(month) {
      return 0;
    },

    parse(){
      this.zhuanhuan=this.getProjectNum();
      this.ruleFrom.meiYon=parseInt(this.zhuanhuan);
    },

    // 跳转返回指定的页面
    // goBack() {
    //   this.$router.push({
    //     path: '/auditList'
    //   })
    // },

    // update(numbers,proId){
    //
    //   this.axios.get("http://localhost:8088/update-details",{params:{numbers:numbers,proId:proId}})
    //       .then((v) => {
    //         this.$message("修改成功");
    //       })
    // },

    // updateById() {
    //   var json=JSON.stringify(this.tableDetails);
    //
    //   this.axios.post("http://localhost:8088/update-drugstore",json,{headers:{"Content-Type":"application/x-www-from-urlencoded"}})
    //
    //       .then((v) => {
    //
    //         this.$message("修改成功");
    //         this.$router.push({
    //           path: '/return'
    //         })
    //       })
    // }
    // ,



    // 初始页currentPage、初始每页数据数pagesize和数据data
    handleSizeChange: function (size) {
      this.pagesize = size;
      console.log(this.pagesize)  //每页下拉显示数据
    },
    handleCurrentChange: function(currentPage){
      this.currentPage = currentPage;
      console.log(this.currentPage)  //点击第几页
    },

    selectionLineChangeHandle(val) {
      this.tableDetails = val;
      console.log(this.tableDetails);
      for (var i = 0; i < this.tableDetails.length; i++) {
        console.log('number:' + this.tableDetails[i])

      }
    },
    //小表格提交
    fromCommit() {
      console.log(this.tableDetails);
      for (var i = 0; i < this.tableDetails.length; i++) {
        console.log('id:' + this.tableDetails[i])
        console.log('id:' + this.tableDetails[i])
      }
    },
  },


  randomNumber() {
    const now = new Date()
    let month = now.getMonth() + 1
    let day = now.getDate()
    let hour = now.getHours()
    let minutes = now.getMinutes()
    let seconds = now.getSeconds()
    month = this.setTimeDateFmt(month)
    hour = this.setTimeDateFmt(hour)
    minutes = this.setTimeDateFmt(minutes)
    seconds = this.setTimeDateFmt(seconds)
    return now.getFullYear().toString() + month.toString() + day + hour + minutes + seconds + (Math.round(Math.random() * 23 + 100)).toString()
  },

  created() {

    this.ruleFrom=JSON.parse(this.$route.query.value);
    this.parse();
      service.get("find-audit5",{params:{
          auditId:this.ruleFrom.auditId
        }})
          .then((v) => {
              this.tableData = v.data;
          })
      this.ruleFrom.reportNameVO=Cookies.get('username');
  }

}
</script>


<style scoped>
.whiteSelectBg .el-input.is-disabled .el-input__inner{
  background-color: white;
  color:#606266;
}
*{
  margin: 0px;
  padding: 0px;
}
.xq{
  width: 100%;

  background-color:#E9EEF3;
  padding-top:100px;
  padding-bottom: 100px;
}
.max_box{
  width:100%;
  height:500px;
  margin:auto;
  background-color: #E9EEF3;
}
.xia_box{
  width:850px;
  height:500px;
  background: white;
  margin-left: 360px;
  margin-top: 10px;

}


</style>















